namespace hjc {

	export class IndependaceSystem extends System {

		protected $concerns = [ViewSort];
		protected $indpComps = [];
		protected execute(entities: Entity[], param: TimeParam): void {
			this.$indpComps.forEach(indpComp => {
				if (indpComp instanceof ViewSort && indpComp.checkPfc()) this._sortView(indpComp);
			});
		}

		protected entities(): Entity[] { return []; }

		public addComp(indpComp: Component): void {
			this.$indpComps.push(indpComp);
		}

		private _sortView(vs: ViewSort): void {
			vs.view.$children.sort((c1: egret.DisplayObject, c2: egret.DisplayObject) => {
				if (vs.horizontal) return !!vs.reversed ? c2.x - c1.x : c1.x - c2.x;
				else return !!vs.reversed ? c2.y - c1.y : c1.y - c2.y;
			});
		}
	}
}